package com.service.impl;

import com.dao.CityDAO;
import com.dao.LayCityDAO;
import com.entity.City;
import com.service.LayCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class LayCityServiceImpl implements LayCityService {
    @Autowired
    private LayCityDAO layCityDAO;
    @Override
    public Map selectAllLay(Integer page, Integer limit, String cityName) {
        if (cityName!=null&&!cityName.equals("")){
            cityName="%"+cityName+"%";
        }else {
            cityName=null;
        }
        Integer offset=(page-1)*limit;
        List<City> list=layCityDAO.selectAllLay(offset,limit,cityName);
        Integer count=layCityDAO.selectCount(cityName);
        Map map=new HashMap();
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
        return map;
    }

    @Override
    public Map insert(City city) {
        Integer count = layCityDAO.insert(city);
        Map map = new HashMap();
        if(count>0){
            map.put("isAdd",true);
        }else{
            map.put("isAdd",false);
        }
        return map;
    }
}
